/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.notify.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.notify.dao.NotiMessageDao;
import com.thinkgem.jeesite.modules.notify.entity.NotiMessage;
import com.thinkgem.jeesite.modules.sys.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 推送消息Service
 * @author 陈斌
 * @version 2018-12-13
 */
@Service
@Transactional(readOnly = true)
public class NotiMessageService extends CrudService<NotiMessageDao, NotiMessage> {
    @Autowired
    DictService dictService;
    @Autowired
    private NotiMessageDao notiMessageDao;

	public NotiMessage get(String id) {
		return super.get(id);
	}
	
	public List<NotiMessage> findList(NotiMessage notiMessage) {
		return super.findList(notiMessage);
	}
	
	public Page<NotiMessage> findPage(Page<NotiMessage> page, NotiMessage notiMessage) {
        List<NotiMessage> list = super.findPage(page, notiMessage).getList();
        for (NotiMessage notiMes : list) {
            if (StringUtils.isEmpty(notiMes.getAppedition())) {
                notiMes.setAppedition("全部");
            }
            if (StringUtils.isEmpty(notiMes.getAppid())) {
                notiMes.setAppid("所有应用app");
            }
        }

		return super.findPage(page, notiMessage);
	}
	
	@Transactional(readOnly = false)
	public void save(NotiMessage notiMessage) {
		super.save(notiMessage);
	}
	
	@Transactional(readOnly = false)
	public void delete(NotiMessage notiMessage) {

		super.delete(notiMessage);
	}

	@Transactional(readOnly = false)
    public Integer increaseAndroidSuccess(String msgId) {
        return notiMessageDao.updateAndroidSuccess(msgId);
    }

    @Transactional(readOnly = false)
    public Integer updateAndroidTotal(String msgId, Long pushAndroidToal) {
        return notiMessageDao.updateAndroidTotal(msgId, pushAndroidToal);
    }

    public List<String> getPushMessageTagOrAlias(String dictType) {
        return dictService.getPushMessageTagOrAlias(dictType, null);
    }
}